package com.czy.owner.ui.userinfo;

import android.content.Intent;
import android.text.Editable;
import android.text.Selection;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;

import com.czy.owner.R;
import com.czy.owner.ui.BaseActivity;
import com.czy.owner.utils.PhoneUtils;
import com.czy.owner.widget.MyEditText;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by wangyang on 2017/5/9 0009.
 * 修改用户昵称
 */

public class UpdateUserNameActivity extends BaseActivity {
    @BindView(R.id.et_name_adress)
    MyEditText etNameAdress;
    private String userInfoName;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_update_user_name_adress;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {
        getToolbarTitle().setText(R.string.user_update_name);
        getSubTitle().setText(R.string.save);
        userInfoName = getIntent().getStringExtra("userInfoName");
        if (userInfoName.equals(getString(R.string.user_name_hint))) {
            etNameAdress.setHint(getString(R.string.user_name_hint));
        } else {
            etNameAdress.setText(userInfoName);
        }
        etNameAdress.setSelection(etNameAdress.getText().toString().length());
        PhoneUtils.userNameLengthContrl(UpdateUserNameActivity.this,etNameAdress);
    }

    @Override
    protected void updateViews() {

    }

    //保存
    @OnClick(R.id.toolbar_subtitle)
    public void forgetPassword(View view) {
        if (TextUtils.isEmpty(etNameAdress.getText().toString().trim())) {
            PhoneUtils.ShowToastMessage(UpdateUserNameActivity.this, "昵称不能为空");
            return;
        }

        Intent intent = new Intent();
        intent.putExtra("userInfoName", etNameAdress.getText().toString().trim());
        setResult(UserInfoActivity.USER_NAME, intent);
        finish();
    }


}
